#include <iostream>

class Solution {
public:
    bool isPowerOfThree(int n) {
        if (n == 1) {
            return true;
        }
        int64_t mi = 1;
        while (mi < n) {
            mi *= 3;
            if (mi == n) {
                return true;
            }
        }
        return false;
    }
};